#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "pqcp_test.h"
#include "pqcp_types.h"
#include "pqcp_provider.h"
#include "crypt_eal_provider.h"
#include "crypt_eal_implprovider.h"
#include "crypt_eal_pkey.h"
#include "crypt_errno.h"
#include "crypt_eal_rand.h"

#include "hitls_cert_local.h"
#include "hitls_pki_cert.h"
#include "hitls_pki_types.h"

typedef struct _HITLS_X509_Cert HITLS_X509_Cert;
static PqcpTestResult TestCertPublicKeyParse(const char *certPath, const char *providerAttr)
{
    HITLS_PKI_LibCtx *libCtx = NULL; // 假设已初始化
    HITLS_X509_Cert *cert = NULL;
    
    int32_t ret = HITLS_X509_ProviderCertParseFile(libCtx, providerAttr, "ASN1", certPath, &cert);
   
    if (ret != BSL_SUCCESS) {
        printf("证书解析失败，错误码: %d\n", ret);
        return -1;
    }
    
    printf("证书解析成功！\n");
    
    if (cert) {
        HITLS_X509_CertFree(cert); 
    }
    
    return 0;
}


//单条证书路径测试用例
int32_t TestCertPubkey_1(void)
{
    /* ../../testdata/certs/cert1.der 表示：
       从当前源码目录往上两级，然后进入 testdata/certs/ 目录下的 cert1.der 文件 */
    return TestCertPublicKeyParse("../../testdata/certs/cert1.pem", "pqcp");
}

int32_t PQCP_InitCertPubkeyTestSuite(void)
{
    PqcpTestSuite *suite = PQCP_TestCreateSuite("x509_pubkey", "X.509 证书公钥解析测试");
    if (suite == NULL) return -1;

    PQCP_TestAddCase(suite, "cert1 pubkey parse", "测试 cert1 公钥解析", TestCertPubkey_1);

    return PQCP_TestAddSuite(suite);
}